package com.some.jobdescapp.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.TextView;

import com.some.jobdescapp.R;
import com.some.jobdescapp.bean.JobDescEntity;

import java.util.ArrayList;

public class JobDescActivity extends BaseActivity {

    private TextView contentTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_job_desc);
        contentTextView = findViewById(R.id.content);

        findViewById(R.id.back_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        initData();
    }

    private void initData() {
        ArrayList<JobDescEntity> jobDescEntities = (ArrayList<JobDescEntity>) getIntent().getSerializableExtra("data");
        for (JobDescEntity jobDescEntity : jobDescEntities) {
            contentTextView.append(getTItle(jobDescEntity.getTitle()));
            contentTextView.append("\n");
            contentTextView.append(jobDescEntity.getDesc());
            contentTextView.append("\n");
        }
    }

    private CharSequence getTItle(String title) {
        if (TextUtils.isEmpty(title)) {
            return "";
        }
        SpannableStringBuilder builder = new SpannableStringBuilder(title);
        builder.setSpan(new RelativeSizeSpan(1.2f), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }
}
